// src/anotherStore.tsx
import React, { Dispatch, FC, SetStateAction, useState } from 'react'
import { itemCount } from './helpers/cart'

// 创建上下文对象
export const TotelContext = React.createContext<
    [number, Dispatch<SetStateAction<number>>]
>([0, () => null])

interface Props {
    children: React.ReactNode
}

const AnotherStore: FC<Props> = ({ children }) => {
    // 初始化值并将数据导入到上下文组件中
    const [count, setCount] = useState(itemCount())
    return (
        <TotelContext.Provider value={[count, setCount]}>
            { children }
        </TotelContext.Provider>
    )
}

export default AnotherStore
